//
//  YQForumCell.m
//  iyuanqi
//
//  Created by czl on 2017/7/27.
//  Copyright © 2017年 czl. All rights reserved.
//

#import "YQForumCell.h"

@interface YQForumCell()

@property(nonatomic,strong)UIImageView* imageForumHead;
@property(nonatomic,strong)UILabel* labelForumName;
@property(nonatomic,strong)UILabel* labelForumDesc;

@end

@implementation YQForumCell

+ (NSString *)cellIdentifier {
    return @"YQForumCell";
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
    YQForumCell *cell = (YQForumCell*)[collectionView dequeueReusableCellWithReuseIdentifier:[YQForumCell cellIdentifier] forIndexPath:indexPath];
    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.layer.borderColor = UIColorFromRGB(0xededed).CGColor;
        self.layer.borderWidth = 0.4;
        self.layer.masksToBounds = YES;
        
        [self.contentView addSubview:self.imageForumHead];
        [self.imageForumHead mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.left.mas_equalTo(10);
            make.size.mas_equalTo(60);
        }];
        
        [self.contentView addSubview:self.labelForumName];
        [self.labelForumName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.imageForumHead);
            make.left.mas_equalTo(self.imageForumHead.mas_right).offset(10);
        }];
        
        [self.contentView addSubview:self.labelForumDesc];
        [self.labelForumDesc mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.imageForumHead);
            make.left.mas_equalTo(self.labelForumName);
        }];
    }
    return self;
}

- (void)setForumObject:(YQForumObject*)obj {
    [self.imageForumHead sd_setImageWithURL:[NSURL URLWithString:obj.icon] placeholderImage:[UIImage imageNamed:@"img_default_head"]];
    self.labelForumName.text = obj.name;
    self.labelForumDesc.text = obj.desc;
}

- (UIImageView*)imageForumHead {
    if (!_imageForumHead) {
        _imageForumHead = [[UIImageView alloc]init];
    }
    return _imageForumHead;
}

- (UILabel*)labelForumName {
    if (!_labelForumName) {
        _labelForumName = [[UILabel alloc]init];
        _labelForumName.font = [UIFont systemFontOfSize:16];
        _labelForumName.textColor = UIColorFromRGB(0x333333);
    }
    return _labelForumName;
}

- (UILabel*)labelForumDesc {
    if (!_labelForumDesc) {
        _labelForumDesc = [[UILabel alloc]init];
        _labelForumDesc.font = [UIFont systemFontOfSize:12];
        _labelForumDesc.textColor = UIColorFromRGB(0x999999);
    }
    return _labelForumDesc;
}

@end
